<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>付款信息表 管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}

        .sq-button.sq-button-round.disabled{
            color: rgba(0,0,0,.30);
            background: #eaeaea;
            border: 1px solid #d8d8d8;
            cursor: not-allowed;
        }
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contNo" id="contNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <%--<div class="fieldBox">--%>
                    <%--<div class="label">项目类型</div>--%>
                    <%--<div class="field">--%>
                        <%--&lt;%&ndash;<input name="prjTypCd" id="prjTypCd" data-value="" placeholder="请选择" ltype="combobox">&ndash;%&gt;--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="fieldBox col_33" >
                    <div class="label">项目类型</div>
                    <div class="field">
                        <select name="prjTypCd"  id="prjTypCd" >
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${prjTypCdList}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户姓名</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">实付时间</div>
                    <div class="field">
                        <input ligerui="width: 82" name="actPayTmBg" id="actPayTmBg" type="text" class="ui-datepicker" value="">
                        -
                        <input ligerui="width: 82" name="actPayTmEd" id="actPayTmEd" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">付款金额</div>
                    <div class="field">
                        <input ligerui="width: 82" name="payAmtMin" id="payAmtMin" type="text" class="ui-textbox" value="">
                        -
                        <input ligerui="width: 82" name="payAmtMax" id="payAmtMax" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">放款状态</div>
                    <div class="field">
                        <input name="payStsCd" id="payStsCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">首期款代收</div>
                    <div class="field">
                        <input name="isFstCol" id="isFstCol" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">申请来源</div>
                    <div class="field">
                        <input name="applyResCd" id="applyResCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保险分期</div>
                    <div class="field">
                        <input name="installmentCd" id="installmentCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox col_33" id="searchInsCodeId" <sys:resourceAuth resCd="noThdOrg">style="display: none" </sys:resourceAuth>>
                    <div class="label">第三方机构</div>
                    <div class="field">
                        <select name="insCode"  id="insCode" >
                            <option value="  " selected="selected">--请选择--</option>
                            <c:forEach items="${friBaseList}" var="fri">
                                <option value="${fri.insCode}">${fri.fundRasInsNmShow}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50" id="isSplMfrDiv" >
                    <div class="label">厂商业务</div>
                    <div class="field">
                        <select name="isSplMfr"  id="isSplMfr"  >
                            <option value="  ">请选择</option>
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_33" id="isInsBizDiv" >
                    <div class="label">是否资管业务</div>
                    <div class="field">
                        <select name="isInsBiz"  id="isInsBiz"  >
                            <option value=" "  selected="selected">-请选择-</option>
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">业务归属城市</div>
                    <div class="field">
                        <div class="field">
                            <jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
                                <jsp:param name="regionShowLvl" value="2"/>
                            </jsp:include>
                        </div>
                    </div>
                </div>
                <%--<div class="fieldBox">
                    <div class="label">所属区域</div>
                    <div class="field">
                        <input name="cstMgrRgnCd" id="cstMgrRgnCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>--%>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="norBtn" class="sq-button sq-button-round flowBtn">正常放款</span>
                    <span id="befBtn" class="sq-button sq-button-round flowBtn">提前放款</span>
                    <c:if test="${not empty currentOrgCd and currentOrgCd.indexOf('00000001') != -1}">
                        <span id="befBtn2" class="sq-button sq-button-round flowBtn">提前放款(需上牌)</span>
                        <span id="speBtn" class="sq-button sq-button-round flowBtn">特殊放款</span>
                    </c:if>
                    <c:if test="${not empty currentOrgCd and currentOrgCd.indexOf('00000013') != -1}">
                        <span id="befBtn2" class="sq-button sq-button-round flowBtn">提前放款(需上牌)</span>
                    </c:if>
                    <c:if test="${not empty currentOrgCd and currentOrgCd.indexOf('00000014') != -1}">
                        <span id="befBtn2" class="sq-button sq-button-round flowBtn">提前放款(需上牌)</span>
                    </c:if>
                    <c:if test="${not empty currentOrgCd and currentOrgCd.indexOf('00000005') != -1}">
                        <span id="speBtn" class="sq-button sq-button-round flowBtn">特殊放款</span>
                    </c:if>
                    <span id="xlsBtn" class="sq-button sq-button-round">导出</span>
                    <span id="punctualBtn" class="sq-button sq-button-round flowBtn">准时放款</span>
                    <span id="mtgExpFlowStartBtn" class="sq-button sq-button-round" onclick="addMtgExpFlowStart();" style="display: none">抵押外派</span>
                    <%--<span id="changeBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改</span>--%>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <%--<span id="addAdvanceFlow" class="sq-button sq-button-hasicon"><i class="sqBtnIco_47"></i>发起流程</span>--%>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,callback=null;
    var currentOrgCd = '${currentOrgCd}';
    var mtgExpFlowStartBtnShow = '${mtgExpFlowStartBtnShow}';
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capPayInfo/initList.do',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '合同号', name: 'contNo', width: 140, align: 'left', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 150, align: 'left', enabledSort: false},
                {display: '第三方机构', name: 'fundRasInsNm', width: 150, align: 'left', enabledSort: false},
                {display: '放款金额', name: 'payAmt', width: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.payAmt/100);
                    }
                },
                {display: '实际放款金额', name: 'actPayAmt', width: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.actPayAmt){
                            return '&yen;'+FormatMoney(rowdata.actPayAmt/100);
                        }
                    }
                },
                {display: '实际放款时间', name: 'actPayTm', width: 80, align: 'center', enabledSort: false,render:renderDate},
                {display: '机构实际放款金额', name: 'thdPayAmt', id:"thdPayAmt",width: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.thdPayAmt){
                            return '&yen;'+FormatMoney(rowdata.thdPayAmt/100);
                        }
                    }
                },
                {display: '机构实际放款时间', name: 'thdPayDt', id:"thdPayDt",width: 100, align: 'center', enabledSort: false,render:renderDate},
                {display: '首期款代收', name: 'isFstColNm', width: 80, align: 'center', enabledSort: false},
                {display: '放款状态', name: 'payStsCdNm', width: 80, align: 'center', enabledSort: false},
                {display: '申请来源', name: 'applyResCdNm', width: 80, align: 'center', enabledSort: false},
                {display: '计时时间', name: 'applyDt', width: 150, align: 'center', enabledSort: false,render:renderDateDetail},
                {display: '流程编号', name: 'prInsNo', minWidth: 140, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if(value&&value!="null"){
                            if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_CAR){
                                if(StringUtils.isNotEmpty(rowdata.bizFlag) && rowdata.bizFlag == '2'){
                                    h+='<a href="javascript:commShowFlowForGHYW(';
                                    h+="'"+rowdata.bizFlag+"',";//2018-3-14 by yaoxiurong
                                }else{
                                    h+='<a href="javascript:commShowFlowForCarBiz(';
                                }
                            }else if(StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd==ProjectConstant.CODE_BU_ORG_CD_ZC){
                                h+='<a href="javascript:commShowFlowForSpecialCar(';
                            }else{
                                h+='<a href="javascript:commShowFlow(';
                            }
                            //2018-3-14 by yaoxiurong
                            /* if(StringUtils.isNotEmpty(rowdata.bizFlag) && rowdata.bizFlag == '2'){
                             h+="'"+rowdata.bizFlag+"',";
                             } */
                            h+="'"+rowdata.prInsId+"',";
                            h+="'"+rowdata.audStsCd+"',";
                            h+="'"+rowdata.id+"'";
                            h+=')">'+value+'</a>'
                        }
                        return h;
                    },
                },
                {display: '项目类型', name: 'prjTypCdNm', width: 80, align: 'center', enabledSort: false},
                { display: '是否资管业务', name: 'isInsBiz', minWidth: 100 , enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        if (rowdata.isInsBiz == 1) {
                            return "是";
                        } else if (rowdata.isInsBiz == 0) {
                            return "否";
                        }
                    }
                },
                { display: '是否厂商业务', name: 'isSplMfr', minWidth: 100 , enabledSort:true,
                    render: function (rowdata, rowindex, value, column) {
                        if (rowdata.isSplMfr == 1) {
                            return "是";
                        } else if (rowdata.isSplMfr == 0) {
                            return "否";
                        }
                    }
                },
                {display: '客户经理', name: 'cstMgrNm', width: 80, align: 'center', enabledSort: false},
                {display: '所属事业部', name: 'buOrgCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '省公司', name: 'prOrgCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '分公司', name: 'cyOrgCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '业务归属城市', name: 'rgnCityCd', width: 100, align: 'center', enabledSort: false},
                /*{display: '所属区域', name: 'cstMgrRgnCdNm', width: 100, align: 'center', enabledSort: false},*/
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            isSingleCheck:true,
            onSelectRow:function(rowdata, rowid, rowobj){
                if(rowdata.payStsCd!="1"&&rowdata.payStsCd!="4"){
                    $(".flowBtn").addClass("disabled").attr("flowKey","");
                    return;
                }

                //重卡事业部 根据供应商支持的放款流程控制按钮
                if(rowdata.buOrgCd=="00000001" || rowdata.buOrgCd=="00000014"){
                    $(".flowBtn").addClass("disabled").attr("flowKey","");
                    if(rowdata.supportFlowList && rowdata.supportFlowList.length>0){
                        for(var i=0;i<rowdata.supportFlowList.length;i++){
                            var flowTyp = rowdata.supportFlowList[i];
                            if(flowTyp.payTypCd=="1"){
                                $("#norBtn").removeClass("disabled").attr("flowKey",flowTyp.flowKey);
                            }else if(flowTyp.payTypCd=="2"){
                                $("#befBtn").removeClass("disabled").attr("flowKey",flowTyp.flowKey);
                            }else if(flowTyp.payTypCd=="3"){
                                $("#speBtn").removeClass("disabled").attr("flowKey",flowTyp.flowKey);
                            }else if(flowTyp.payTypCd=="5"){
                                $("#punctualBtn").removeClass("disabled").attr("flowKey",flowTyp.flowKey);
                            }else{
                                $("#befBtn2").removeClass("disabled").attr("flowKey",flowTyp.flowKey);
                            }
                        }
                    }
                }else{
                    $(".flowBtn").removeClass("disabled").attr("flowKey","");
                }
            },
            onUnSelectRow:function(rowdata, rowid, rowobj){
                $(".flowBtn").removeClass("disabled").attr("flowKey","");
            }
        });
        //false不显示，true显示
        grid.toggleCol('thdPayDt', false);
        grid.toggleCol('thdPayAmt', false);
        grid.setHeight(100);

        $("#searchBar").ligerForm();
        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("buOrgCd").setData(${buOrgCdList});
        //项目类型
        <%--$("#prjTypCd").ligerComboBox({--%>
            <%--valueField: 'key',--%>
            <%--textField: 'value'--%>
        <%--});--%>
        <%--liger.get("prjTypCd").setData(${prjTypCdList});--%>
        //付款状态
        $("#payStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("payStsCd").setData(${payStsCdList});
        //申请来源
        $("#applyResCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("applyResCd").setData(${applyResCdList});
        //首期款代收
        $("#isFstCol").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("isFstCol").setData(${fstColCdList});
        //保险分期
        $("#installmentCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("installmentCd").setData(${fstColCdList});
        //所属区域
        /*$("#cstMgrRgnCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("cstMgrRgnCd").setData(${regionList});*/

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {

            // 归属城市校验，查询条件选择省后，市必须  rgnProvCd  rgnCityCd
            if ($("#rgnProvCd").val()!=""&&$("#rgnCityCd").val()=="") {
                $.ligerDialog.SQalert({content: "归属城市不能为空", SQ_type: "warning"});
                return;
            }
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

        /* 正常放款 */
        $("#norBtn").click(function (event) {
            if($("#norBtn").attr("class").indexOf("disabled")>0){
                return;
            }
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            /*if(StringUtils.isNotEmpty(selectedRows[0].prjTypCd) && selectedRows[0].prjTypCd =="CPYW"){
             $.ligerDialog.SQalert({content: "城配业务只能发起特殊放款", SQ_type: "warning"});
             return;
             }*/
            var wait_dialog;
            var isOk = true;//是否验证通过
            //验证客户风险状态
            <%--$.ajax({--%>
            <%--    type: 'get',--%>
            <%--    dataType:'json',--%>
            <%--    async: false,--%>
            <%--    &lt;%&ndash;url: '<%=path%>/risk/rskCstSignLog/searchRskSts.do?prjId='+selectedRows[0].prjId,&ndash;%&gt;--%>
            <%--    url: '<%=path%>/project/audit/checkRiskSign.do?flow=CAP&prjId='+selectedRows[0].prjId+'&capPayId='+selectedRows[0].id,--%>
            <%--    beforeSend: function(){--%>
            <%--        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });--%>
            <%--    },--%>
            <%--    success:function(data){--%>
            <%--        wait_dialog.close();--%>
            <%--        if(data.success != 1){--%>
            <%--            $.ligerDialog.SQalert({content: data.info, SQ_type: "error",SQ_showButtons : true});--%>
            <%--            isOk = false;--%>
            <%--        }--%>
            <%--    }--%>
            <%--});--%>
            if(!isOk){
                return;
            }

            var flowKey = "";
            if($("#norBtn").attr("flowKey")){
                flowKey = $("#norBtn").attr("flowKey");
            }
            validateIns(selectedRows[0],1,flowKey);
        });

        /* 准时放款 */
        $("#punctualBtn").click(function (event) {
            if($("#punctualBtn").attr("class").indexOf("disabled")>0){
                return;
            }
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            /*if(StringUtils.isNotEmpty(selectedRows[0].prjTypCd) && selectedRows[0].prjTypCd =="CPYW"){
             $.ligerDialog.SQalert({content: "城配业务只能发起特殊放款", SQ_type: "warning"});
             return;
             }*/

            var wait_dialog;
            var isOk = true;//是否验证通过
            //验证客户风险状态
            <%--$.ajax({--%>
            <%--    type: 'get',--%>
            <%--    dataType:'json',--%>
            <%--    async: false,--%>
            <%--    &lt;%&ndash;url: '<%=path%>/risk/rskCstSignLog/searchRskSts.do?prjId='+selectedRows[0].prjId,&ndash;%&gt;--%>
            <%--    url: '<%=path%>/project/audit/checkRiskSign.do?flow=CAP&prjId='+selectedRows[0].prjId+'&capPayId='+selectedRows[0].id,--%>
            <%--    beforeSend: function(){--%>
            <%--        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });--%>
            <%--    },--%>
            <%--    success:function(data){--%>
            <%--        wait_dialog.close();--%>
            <%--        if(data.success != 1){--%>
            <%--            $.ligerDialog.SQalert({content: data.info, SQ_type: "error",SQ_showButtons : true});--%>
            <%--            isOk = false;--%>
            <%--        }--%>
            <%--    }--%>
            <%--});--%>
            if(!isOk){
                return;
            }

            var flowKey = "";
            if($("#punctualBtn").attr("flowKey")){
                flowKey = $("#punctualBtn").attr("flowKey");
            }
            validateIns(selectedRows[0],5,flowKey);//准时放款
        });

        /* 提前放款 */
        $("#befBtn").click(function (event) {
            if($("#befBtn").attr("class").indexOf("disabled")>0){
                return;
            }
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            /*if(StringUtils.isNotEmpty(selectedRows[0].prjTypCd) && selectedRows[0].prjTypCd =="CPYW"){
             $.ligerDialog.SQalert({content: "城配业务只能发起特殊放款", SQ_type: "warning"});
             return;
             }*/
            if(selectedRows[0].bizFlag != null && selectedRows[0].bizFlag == '2'){
                top.$.ligerDialog.SQalert({content: "除狮桥项目，其他项目仅支持发起正常放款流程", SQ_type: "warning",SQ_showButtons:true});
                return;
            }
            //兴业金租
            if(selectedRows[0].bizFlag != null && selectedRows[0].bizFlag == 'xyfl' && selectedRows[0].prjTypCd == 'ESCJYD' && selectedRows[0].prjTypCd == 'OWNJYD'){
                top.$.ligerDialog.SQalert({content: "兴业金租业务禁止提前放款", SQ_type: "warning",SQ_showButtons:true});
                return;
            }
            var wait_dialog;
            var isOk = true;//是否验证通过
            //验证客户风险状态
            <%--$.ajax({--%>
            <%--    type: 'get',--%>
            <%--    dataType:'json',--%>
            <%--    async: false,--%>
            <%--    &lt;%&ndash;url: '<%=path%>/risk/rskCstSignLog/searchRskSts.do?prjId='+selectedRows[0].prjId,&ndash;%&gt;--%>
            <%--    url: '<%=path%>/project/audit/checkRiskSign.do?flow=CAP&prjId='+selectedRows[0].prjId+'&capPayId='+selectedRows[0].id,--%>
            <%--    beforeSend: function(){--%>
            <%--        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });--%>
            <%--    },--%>
            <%--    success:function(data){--%>
            <%--        wait_dialog.close();--%>
            <%--        if(data.success != 1){--%>
            <%--            $.ligerDialog.SQalert({content: data.info, SQ_type: "error",SQ_showButtons : true});--%>
            <%--            isOk = false;--%>
            <%--        }--%>
            <%--    }--%>
            <%--});--%>
            if(!isOk){
                return;
            }

            var flowKey = "";
            if($("#befBtn").attr("flowKey")){
                flowKey = $("#befBtn").attr("flowKey");
            }
            validateIns(selectedRows[0],2,flowKey);
        });
        /* 提前放款（需上牌）*/
        $("#befBtn2").click(function (event) {
            if($("#befBtn2").attr("class").indexOf("disabled")>0){
                return;
            }
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if(selectedRows[0].bizFlag != null && selectedRows[0].bizFlag == '2'){
                top.$.ligerDialog.SQalert({content: "除狮桥项目，其他项目仅支持发起正常放款流程", SQ_type: "warning",SQ_showButtons:true});
                return;
            }

            var wait_dialog;
            var isOk = true;//是否验证通过
            //验证客户风险状态
            <%--$.ajax({--%>
            <%--    type: 'get',--%>
            <%--    dataType:'json',--%>
            <%--    async: false,--%>
            <%--    &lt;%&ndash;url: '<%=path%>/risk/rskCstSignLog/searchRskSts.do?prjId='+selectedRows[0].prjId,&ndash;%&gt;--%>
            <%--    url: '<%=path%>/project/audit/checkRiskSign.do?flow=CAP&prjId='+selectedRows[0].prjId+'&capPayId='+selectedRows[0].id,--%>
            <%--    beforeSend: function(){--%>
            <%--        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });--%>
            <%--    },--%>
            <%--    success:function(data){--%>
            <%--        wait_dialog.close();--%>
            <%--        if(data.success != 1){--%>
            <%--            $.ligerDialog.SQalert({content: data.info, SQ_type: "error",SQ_showButtons : true});--%>
            <%--            isOk = false;--%>
            <%--        }--%>
            <%--    }--%>
            <%--});--%>
            if(!isOk){
                return;
            }

            var flowKey = "";
            if($("#befBtn2").attr("flowKey")){
                flowKey = $("#befBtn2").attr("flowKey");
            }
            validateIns(selectedRows[0],4,flowKey);
        });
        /* 特殊放款 */
        $("#speBtn").click(function (event) {
            if($("#speBtn").attr("class").indexOf("disabled")>0){
                return;
            }
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if(selectedRows[0].bizFlag != null && selectedRows[0].bizFlag == '2'){
                top.$.ligerDialog.SQalert({content: "除狮桥项目，其他项目仅支持发起正常放款流程", SQ_type: "warning",SQ_showButtons:true});
                return;
            }

            if(ProjectConstant.CODE_BU_ORG_CD_ZK == selectedRows[0].buOrgCd || ProjectConstant.CODE_BU_ORG_CD_CAR == selectedRows[0].buOrgCd ){
                if(ProjectConstant.CODE_BU_ORG_CD_ZK == selectedRows[0].buOrgCd && selectedRows[0].prjTypCd !="CPYW"){
                    $.ligerDialog.SQalert({content: LogUtils.LOG_FOLW_PAY_INFO_CHECK_TYPE, SQ_type: "warning",SQ_showButtons:true});
                    return;
                }else if(ProjectConstant.CODE_BU_ORG_CD_CAR == selectedRows[0].buOrgCd && selectedRows[0].isNew ==1){
                    $.ligerDialog.SQalert({content: "新车不能发起特殊放款流程！", SQ_type: "warning",SQ_showButtons:true});
                    return;
                }
            }else{
                $.ligerDialog.SQalert({content: "暂不支持发起特殊放款流程！", SQ_type: "warning",SQ_showButtons:true});
                return;
            }

            var wait_dialog;
            var isOk = true;//是否验证通过
            //验证客户风险状态
            <%--$.ajax({--%>
            <%--    type: 'get',--%>
            <%--    dataType:'json',--%>
            <%--    async: false,--%>
            <%--    &lt;%&ndash;url: '<%=path%>/risk/rskCstSignLog/searchRskSts.do?prjId='+selectedRows[0].prjId,&ndash;%&gt;--%>
            <%--    url: '<%=path%>/project/audit/checkRiskSign.do?flow=CAP&prjId='+selectedRows[0].prjId+'&capPayId='+selectedRows[0].id,--%>
            <%--    beforeSend: function(){--%>
            <%--        wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });--%>
            <%--    },--%>
            <%--    success:function(data){--%>
            <%--        wait_dialog.close();--%>
            <%--        if(data.success != 1){--%>
            <%--            $.ligerDialog.SQalert({content: data.info, SQ_type: "error",SQ_showButtons : true});--%>
            <%--            isOk = false;--%>
            <%--        }--%>
            <%--    }--%>
            <%--});--%>
            if(!isOk){
                return;
            }

            var flowKey = "";
            if($("#speBtn").attr("flowKey")){
                flowKey = $("#speBtn").attr("flowKey");
            }
            validateIns(selectedRows[0],3,flowKey);
        });

        /*导出*/
        $("#xlsBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '<%=path%>/capital/capPayInfo/exportPayList.do',
                data:data,
                beforeSend:function(){
                    wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        window.open(msg.data);
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });

        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id=selectedRows[0].id;
            $.ligerDialog.open({
                cls: 'noBorder_Dialog',
                width: 550,
                height: 500,
                title: '修改付款信息表',
                url:'<%=path%>/capital/capPayInfo/toModifyPage.do?id='+_id
            });
            //Add_navTab('CapPayInfo_2'+_id, "修改付款信息表", '<%=path%>/capital/capPayInfo/toModifyPage.do?id='+_id, callback);
        });

        if (mtgExpFlowStartBtnShow != null && mtgExpFlowStartBtnShow == 'true') {
            $("#mtgExpFlowStartBtn").removeAttr("style");
        }

        //发起流程
        $("#addAdvanceFlow").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            if(selectedRows[0].payStsCd!=1 && selectedRows[0].payStsCd!=4){
                top.$.ligerDialog.SQalert({content: "已申请放款请勿重复申请", SQ_type: "warning"});
                return;
            }
            var modelTyp = FlowConstant.FLOW_MODEL_TYP_PAY;
            var flowDialog = $.ligerDialog.SQopen({
                url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
                width: 700,
                height:400,
                title : '请选择要发起的流程',
                buttons: [{
                    text: "确定", type: 'ok', cls: 'sq-button sq-button-round',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'sq-button sq-button-round',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
                ],
                onClose: function () {
                    var json = flowDialog._DATA;
                    if(!json){
                        return;
                    }
                    var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
                    var _id = selectedRows[0].id;
                    $.ajax({
                        type: 'post',
                        dataType:'json',
                        data:{
                            id:_id,
                            procDefKey:json.procDefKey,
                            procDefId:json.procDefId,
                            procNo:json.procNo
                        },
                        url: '<%=path%>/capPay/flow/addFlowStart.do',
                        success:function(msg){
                            wait_dialog.close();
                            if(msg.success == 1){
                                if(msg.data){
                                    $.ligerDialog.SQalert({
                                        SQ_showButtons: true,
                                        SQ_onBtnclick: function (item, Dialog) {
                                        },
                                        content: msg.info + LogUtils.LOG_FLOW_NEXT_TASK_OPERATOR + msg.data
                                    });
                                    //$.ligerDialog.SQalert({content: msg.info+" 下一节点操作人："+msg.data,SQ_type: "success"});
                                }else{
                                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
                                }
                                grid.reload();
                            }else{
                                $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                            }
                        }
                    });
                }
            });
        });

    });

    //验证保险
    function validateIns(data,type,flowKey){
        if(data.payStsCd!=1&&data.payStsCd!=4){//未申请或申请不通过
            top.$.ligerDialog.SQalert({content: "已申请放款请勿重复申请", SQ_type: "warning"});
            return;
        }
        if(data.buOrgCd != null && '' !=data.buOrgCd && ProjectConstant.CODE_BU_ORG_CD_ZC == data.buOrgCd){//专车事业部
            if(currentOrgCd.indexOf(ProjectConstant.CODE_ORG_CD_YZDG) >= 0){//以租代购
                Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPageBySpecialCar.do?entrance=0&&rcptUntIsMdf=2&id='+data.id+"&payTypCd="+type+"&operateInsPlc="+'1', callback);
            }else{
                Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPageBySpecialCar.do?entrance=0&rcptUntIsMdf=2&id='+data.id+"&payTypCd="+type+"&operateInsPlc="+'1', callback);
            }
        }else{
            if(data.bizFlag != null && data.bizFlag == '2'){//形式直租(乘用车)
                Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPage.do?entrance=3&id='+data.id+"&payTypCd="+type+"&bizFlag="+data.bizFlag+"&operateInsPlc="+'1', callback);
            }else{//回租  其他
                Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPage.do?entrance=3&id='+data.id+"&payTypCd="+type+"&flowKey="+flowKey+"&operateInsPlc="+'1', callback);
            }
        }

        <%--if(ProjectConstant.CODE_BU_ORG_CD_XNY == data.buOrgCd &&(type==1 || type==2 || type==4 ) && data.prjTypCd == "CPYW"){//新能源事业部--%>
        <%--    if(data.bizFlag != null && data.bizFlag == '2'){//形式直租(乘用车)--%>
        <%--        Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPage.do?entrance=3&id='+data.id+"&payTypCd="+type+"&bizFlag="+data.bizFlag, callback);--%>
        <%--    }else{//回租  其他--%>
        <%--        Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPage.do?entrance=3&id='+data.id+"&payTypCd="+type+"&flowKey="+flowKey, callback);--%>
        <%--    }--%>
        <%--}--%>

        /*var wait_dialog;
         $.ajax({
         type: 'post',
         dataType: 'json',
         data: {buOrgCd: data.buOrgCd,prjTypCd:data.prjTypCd,paySchId:data.paySchId,prjPrdDtlId:data.prjPrdDtlId,prjPrdId:data.prjPrdId,payTypCd:type},
         url: '<%=path%>/insurance/insTypCfgR/validate.do',
         beforeSend: function () {
         wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
         },
         success: function (msg) {
         wait_dialog.close();
         if (msg.success == 1) {
         Add_navTab("CapPayInfo_"+data.id, "付款申请单", '<%=path%>/capital/capPayInfo/toAddPage.do?id='+data.id+"&payTypCd="+type, callback);
         } else {
         top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error",SQ_showButtons : true,});
         }
         }
         });*/
    }

    //发起抵押外派流程
    function addMtgExpFlowStart() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        if (selectedRows[0].prjTypCd != 'CTYW') {
            top.$.ligerDialog.SQalert({content: "非传统业务不支持发起抵押外派流程", SQ_type: "warning", SQ_showButtons: true});
            return;
        }
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if (flag == false) {
                return;
            }
            var capPayId = selectedRows[0].id;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {
                    capPayId: capPayId
                },
                url: '<%=path%>/expatriate/expBizManRec/mortgateExpFlowStart.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        UIUtils.alertSuccessHold1(msg.info);
                        grid.reload();
                    } else {
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        });
    }

    //显示流程
    function commShowFlow(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capPay/flow/toAdditionalInfoPage.do?version=2@@capPayId=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }


    //显示流程-汽车金融工行业务
    function commShowFlowForGHYW(_bizFlag,_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPage.do?accCtrl=1@@ctrlKey=3@@bizFlag="+_bizFlag+"@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //显示流程-汽车金融
    function commShowFlowForCarBiz(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPage.do?accCtrl=1@@ctrlKey=3@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //显示流程-专车事业部
    function commShowFlowForSpecialCar(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/capital/capPayInfo/toAddPageBySpecialCar.do?entrance=0@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_businessKey,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    //格式化时间
    function renderDateDetail(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>

</body>
</html>
